//
//  WebTableViewCell.m
//  CommonFrame
//
//  Created by Bang-guo on 15/7/22.
//  Copyright (c) 2015年 guobang. All rights reserved.
//

#import "WebTableViewCell.h"

@implementation WebTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubViews];
        
    }
    
    
    return self;
    
}

-(void)createSubViews {
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
    [self.contentView addSubview:self.imageV];
    
    
    self.contentL = [[BaseLabel alloc] initWithFrame:CGRectMake(5, self.imageV.frame.size.height + 5, WIDTH - 10, 1000)];
    [self.contentView addSubview:self.contentL];
    
    
}

-(void)setImageStr:(NSString *)imageStr {
    
    if (_imageStr != imageStr) {
        
        _imageStr = imageStr;
        
//        [self.imageV sd_setImageWithURL:[NSURL URLWithString:imageStr]];
                [self.self.imageV sd_setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage imageNamed:@"icon1024.png"]];
    }
    
    
}


-(void)setContentStr:(NSString *)contentStr {
    
    if (_contentStr != contentStr) {
        
        _contentStr = contentStr;
    }
    
    self.contentL.text = contentStr;
    self.contentL.numberOfLines = 0;
    self.contentL.frame = CGRectMake(5, self.imageV.frame.size.height + 5, WIDTH - 10, [self heightCustom:contentStr]);
    
    
}
-(CGFloat)heightCustom:(NSString *)content {
    //参数1.设置计算内容的宽度
    //参数2.设置计算高度
    //参数3.设置字体大小属性
    //参数4.系统备用参数,设置为nil
    
    //其中宽度一定与消失内容的label宽度一致,否则不准确
    CGSize size = CGSizeMake(WIDTH, 100000);
    
    //字体大小一定与显示内容的label字体大小一致,默认 17
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName];
    
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    
    return frame.size.height;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
